home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / krylov_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.1 KB  |  52 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Krylov matrix.
  4.  
  5. // Syntax:    K = krylov ( A , x , j )
  6.  
  7. // Description:
  8.  
  9. //    K is the Krylov matrix
  10. //        [x, Ax, A^2x, ..., A^(j-1)x],
  11. //    where A is an n-by-n matrix and x is an n-vector.
  12.  
  13. //      Defaults: x = ONES(n,1), j = n.
  14.  
  15. //    krylov(n) is the same as krylov(rand(n,n)).
  16.  
  17. //      Reference:
  18. //       G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
  19. //       Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369.
  20.  
  21. //    This file is a translation of krylov.m from version 2.0 of
  22. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  23. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  24.  
  25. //-------------------------------------------------------------------//
  26.  
  27. krylov = function ( A , x, j )
  28. {
  29.   local (A, x, j)
  30.  
  31.   n = A.nr;
  32.  
  33.   if (n == 1)    // Handle special case A = scalar.
  34.   {
  35.     n = A;
  36.     rand("normal", 0, 1);
  37.     A = rand(n,n);
  38.   }
  39.  
  40.   if (!exist (j)) { j = n; }
  41.   if (!exist (x)) { x = ones(n,1); }
  42.  
  43.   B = ones(n,j);
  44.   B[;1] = x[:];
  45.   for (i in 2:j)
  46.   {
  47.     B[;i] = A*B[;i-1];
  48.   }
  49.  
  50.   return B;
  51. };
  52.